using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Runtime.CompilerServices;
using PickGold.Charting;

namespace PickGold.Charting.ChartTypes
{
	internal class FastPointChart : IChartType, IDisposable
	{
		internal bool chartArea3DEnabled;
		internal Matrix3D matrix3D;
		internal float seriesZCoordinate;

		public void AddSmartLabelMarkerPositions(CommonElements common, ChartArea area, Series series, ArrayList list)
		{
		}

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing)
		{
		}

		protected virtual void DrawMarker(ChartGraphics graph, DataPoint point, int pointIndex, PointF location, MarkerStyle markerStyle, int markerSize, Brush brush, Pen borderPen)
		{
			int num;
			if (this.chartArea3DEnabled)
			{
				Point3D[] pointdArray = new Point3D[1];
				location = graph.GetRelativePoint(location);
				pointdArray[0] = new Point3D(location.X, location.Y, this.seriesZCoordinate);
				this.matrix3D.TransformPoints(pointdArray);
				location.X = pointdArray[0].X;
				location.Y = pointdArray[0].Y;
				location = graph.GetAbsolutePoint(location);
			}
			RectangleF rect = new RectangleF(location.X - (((float)markerSize) / 2f), location.Y - (((float)markerSize) / 2f), (float)markerSize, (float)markerSize);
			switch (markerStyle)
			{
				case MarkerStyle.Square:
					graph.FillRectangle(brush, rect);
					if (borderPen != null)
					{
						graph.DrawRectangle(borderPen, (int)Math.Round((double)rect.X, 0), (int)Math.Round((double)rect.Y, 0), (int)Math.Round((double)rect.Width, 0), (int)Math.Round((double)rect.Height, 0));
					}
					goto Label_065F;

				case MarkerStyle.Circle:
					graph.FillEllipse(brush, rect);
					if (borderPen != null)
					{
						graph.DrawEllipse(borderPen, rect);
					}
					goto Label_065F;

				case MarkerStyle.Diamond:
					{
						PointF[] tfArray3 = new PointF[4];
						tfArray3[0].X = rect.X;
						tfArray3[0].Y = rect.Y + (rect.Height / 2f);
						tfArray3[1].X = rect.X + (rect.Width / 2f);
						tfArray3[1].Y = rect.Top;
						tfArray3[2].X = rect.Right;
						tfArray3[2].Y = rect.Y + (rect.Height / 2f);
						tfArray3[3].X = rect.X + (rect.Width / 2f);
						tfArray3[3].Y = rect.Bottom;
						graph.FillPolygon(brush, tfArray3);
						if (borderPen != null)
						{
							graph.DrawPolygon(borderPen, tfArray3);
						}
						goto Label_065F;
					}
				case MarkerStyle.Triangle:
					{
						PointF[] tfArray4 = new PointF[3];
						tfArray4[0].X = rect.X;
						tfArray4[0].Y = rect.Bottom;
						tfArray4[1].X = rect.X + (rect.Width / 2f);
						tfArray4[1].Y = rect.Top;
						tfArray4[2].X = rect.Right;
						tfArray4[2].Y = rect.Bottom;
						graph.FillPolygon(brush, tfArray4);
						if (borderPen != null)
						{
							graph.DrawPolygon(borderPen, tfArray4);
						}
						goto Label_065F;
					}
				case MarkerStyle.Cross:
					{
						float num2 = (float)Math.Ceiling((double)(((float)markerSize) / 4f));
						float num3 = markerSize;
						PointF[] pts = new PointF[12];
						pts[0].X = location.X - (num3 / 2f);
						pts[0].Y = location.Y + (num2 / 2f);
						pts[1].X = location.X - (num3 / 2f);
						pts[1].Y = location.Y - (num2 / 2f);
						pts[2].X = location.X - (num2 / 2f);
						pts[2].Y = location.Y - (num2 / 2f);
						pts[3].X = location.X - (num2 / 2f);
						pts[3].Y = location.Y - (num3 / 2f);
						pts[4].X = location.X + (num2 / 2f);
						pts[4].Y = location.Y - (num3 / 2f);
						pts[5].X = location.X + (num2 / 2f);
						pts[5].Y = location.Y - (num2 / 2f);
						pts[6].X = location.X + (num3 / 2f);
						pts[6].Y = location.Y - (num2 / 2f);
						pts[7].X = location.X + (num3 / 2f);
						pts[7].Y = location.Y + (num2 / 2f);
						pts[8].X = location.X + (num2 / 2f);
						pts[8].Y = location.Y + (num2 / 2f);
						pts[9].X = location.X + (num2 / 2f);
						pts[9].Y = location.Y + (num3 / 2f);
						pts[10].X = location.X - (num2 / 2f);
						pts[10].Y = location.Y + (num3 / 2f);
						pts[11].X = location.X - (num2 / 2f);
						pts[11].Y = location.Y + (num2 / 2f);
						Matrix matrix = new Matrix();
						matrix.RotateAt(45f, location);
						matrix.TransformPoints(pts);
						matrix.Dispose();
						graph.FillPolygon(brush, pts);
						if (borderPen != null)
						{
							graph.DrawPolygon(borderPen, pts);
						}
						goto Label_065F;
					}
				case MarkerStyle.Star4:
				case MarkerStyle.Star5:
				case MarkerStyle.Star6:
				case MarkerStyle.Star10:
					num = 4;
					if (markerStyle != MarkerStyle.Star5)
					{
						if (markerStyle == MarkerStyle.Star6)
						{
							num = 6;
						}
						else if (markerStyle == MarkerStyle.Star10)
						{
							num = 10;
						}
						break;
					}
					num = 5;
					break;

				default:
					throw new InvalidOperationException(SR.ExceptionFastPointMarkerStyleUnknown);
			}
			PointF[] points = graph.CreateStarPolygon(rect, num);
			graph.FillPolygon(brush, points);
			if (borderPen != null)
			{
				graph.DrawPolygon(borderPen, points);
			}
		Label_065F:
			if (this.Common.ProcessModeRegions)
			{
				this.Common.HotRegionsList.AddHotRegion(graph.GetRelativeRectangle(rect), point, point.series.Name, pointIndex);
			}
		}

		public virtual Image GetImage(ChartTypeRegistry registry)
		{
			return (Image)registry.ResourceManager.GetObject(this.Name + "ChartType");
		}

		public virtual LegendImageStyle GetLegendImageStyle(Series series)
		{
			return LegendImageStyle.Marker;
		}

		public virtual double GetYValue(CommonElements common, ChartArea area, Series series, DataPoint point, int pointIndex, int yValueIndex)
		{
			return point.YValues[yValueIndex];
		}

		public virtual void Paint(ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
		{
			this.Common = common;
			this.Graph = graph;
			if (area.Area3DStyle.Enable3D)
			{
				this.chartArea3DEnabled = true;
				this.matrix3D = area.matrix3D;
			}
			else
			{
				this.chartArea3DEnabled = false;
			}
			foreach (Series series in common.DataManager.Series)
			{
				if (((string.Compare(series.ChartTypeName, this.Name, true, CultureInfo.CurrentCulture) != 0) || (series.ChartArea != area.Name)) || !series.IsVisible())
				{
					continue;
				}
				if (this.chartArea3DEnabled)
				{
					float num;
					area.GetSeriesZPositionAndDepth(series, out num, out this.seriesZCoordinate);
					this.seriesZCoordinate += num / 2f;
				}
				Axis axis = area.GetAxis(AxisName.X, series.XAxisType, area.Area3DStyle.Enable3D ? string.Empty : series.XSubAxisName);
				Axis axis2 = area.GetAxis(AxisName.Y, series.YAxisType, area.Area3DStyle.Enable3D ? string.Empty : series.YSubAxisName);
				double viewMinimum = axis.ViewMinimum;
				double viewMaximum = axis.ViewMaximum;
				double num4 = axis2.ViewMinimum;
				double num5 = axis2.ViewMaximum;
				float width = ((float)series.MarkerSize) / 3f;
				if (series.IsCustomPropertySet("PermittedPixelError"))
				{
					float num7;
					string s = series["PermittedPixelError"];
					if (!float.TryParse(s, NumberStyles.Any, CultureInfo.CurrentCulture, out num7))
					{
						throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid2("PermittedPixelError"));
					}
					width = num7;
					if ((width < 0f) || (width > 1f))
					{
						throw new InvalidOperationException(SR.ExceptionCustomAttributeIsNotInRange0to1("PermittedPixelError"));
					}
				}
				SizeF relativeSize = graph.GetRelativeSize(new SizeF(width, width));
				SizeF ef2 = graph.GetRelativeSize(new SizeF((float)viewMinimum, (float)num4));
				double num8 = Math.Abs((double)(axis.PositionToValue((double)(ef2.Width + relativeSize.Width), false) - axis.PositionToValue((double)ef2.Width, false)));
				double num9 = Math.Abs((double)(axis2.PositionToValue((double)(ef2.Height + relativeSize.Height), false) - axis2.PositionToValue((double)ef2.Height, false)));
				SolidBrush brush = new SolidBrush(series.MarkerColor.IsEmpty ? series.Color : series.MarkerColor);
				SolidBrush brush2 = new SolidBrush(series.EmptyPointStyle.MarkerColor.IsEmpty ? series.EmptyPointStyle.Color : series.EmptyPointStyle.MarkerColor);
				Pen pen = null;
				Pen pen2 = null;
				if (!series.MarkerBorderColor.IsEmpty && (series.MarkerBorderWidth > 0))
				{
					pen = new Pen(series.MarkerBorderColor, (float)series.MarkerBorderWidth);
				}
				if (!series.EmptyPointStyle.MarkerBorderColor.IsEmpty && (series.EmptyPointStyle.MarkerBorderWidth > 0))
				{
					pen2 = new Pen(series.EmptyPointStyle.MarkerBorderColor, (float)series.EmptyPointStyle.MarkerBorderWidth);
				}
				bool flag2 = ChartHelper.IndexedSeries(this.Common, new string[] { series.Name });
				int markerSize = series.MarkerSize;
				if ((graph != null) && (graph.Graphics != null))
				{
					markerSize = (int)Math.Max((float)((markerSize * graph.Graphics.DpiX) / 96f), (float)((markerSize * graph.Graphics.DpiY) / 96f));
				}
				int pointIndex = 0;
				double yValue = 0.0;
				double axisValue = 0.0;
				double num14 = 0.0;
				double num15 = 0.0;
				PointF empty = PointF.Empty;
				bool isEmpty = false;
				double num16 = (graph.Common.ChartPicture.Width - 1.0) / 100.0;
				double num17 = (graph.Common.ChartPicture.Height - 1.0) / 100.0;
				MarkerStyle markerStyle = series.MarkerStyle;
				MarkerStyle style2 = series.EmptyPointStyle.MarkerStyle;
				foreach (DataPoint point in series.Points)
				{
					yValue = flag2 ? ((double)(pointIndex + 1)) : point.XValue;
					yValue = axis.GetLogValue(yValue);
					axisValue = axis2.GetLogValue(point.YValues[0]);
					isEmpty = point.IsEmpty;
					if (((yValue < viewMinimum) || (yValue > viewMaximum)) || ((axisValue < num4) || (axisValue > num5)))
					{
						num14 = yValue;
						num15 = axisValue;
						pointIndex++;
					}
					else
					{
						if (((pointIndex > 0) && (Math.Abs((double)(yValue - num14)) < num8)) && (Math.Abs((double)(axisValue - num15)) < num9))
						{
							pointIndex++;
							continue;
						}
						empty.X = (float)(axis.GetLinearPosition(yValue) * num16);
						empty.Y = (float)(axis2.GetLinearPosition(axisValue) * num17);
						MarkerStyle style3 = isEmpty ? style2 : markerStyle;
						if (style3 != MarkerStyle.None)
						{
							this.DrawMarker(graph, point, pointIndex, empty, style3, markerSize, isEmpty ? brush2 : brush, isEmpty ? pen2 : pen);
						}
						num14 = yValue;
						num15 = axisValue;
						pointIndex++;
					}
				}
				brush.Dispose();
				brush2.Dispose();
				if (pen != null)
				{
					pen.Dispose();
				}
				if (pen2 != null)
				{
					pen2.Dispose();
				}
			}
		}

		public virtual bool ApplyPaletteColorsToPoints
		{
			get
			{
				return false;
			}
		}

		public bool CircularChartArea
		{
			get
			{
				return false;
			}
		}

		internal CommonElements Common { set; get; }

		public virtual bool DataPointsInLegend
		{
			get
			{
				return false;
			}
		}

		public virtual bool ExtraYValuesConnectedToYAxis
		{
			get
			{
				return false;
			}
		}

		internal ChartGraphics Graph { set; get; }

		public virtual bool HundredPercent
		{
			get
			{
				return false;
			}
		}

		public virtual bool HundredPercentSupportNegative
		{
			get
			{
				return false;
			}
		}

		public virtual string Name
		{
			get
			{
				return "FastPoint";
			}
		}

		public virtual bool RequireAxes
		{
			get
			{
				return true;
			}
		}

		public virtual bool SecondYScale
		{
			get
			{
				return false;
			}
		}

		public virtual bool SideBySideSeries
		{
			get
			{
				return false;
			}
		}

		public virtual bool Stacked
		{
			get
			{
				return false;
			}
		}

		public bool StackSign
		{
			get
			{
				return false;
			}
		}

		public virtual bool SupportLogarithmicAxes
		{
			get
			{
				return true;
			}
		}

		public virtual bool SupportStackedGroups
		{
			get
			{
				return false;
			}
		}

		public virtual bool SwitchValueAxes
		{
			get
			{
				return false;
			}
		}

		public virtual int YValuesPerPoint
		{
			get
			{
				return 1;
			}
		}

		public virtual bool ZeroCrossing
		{
			get
			{
				return false;
			}
		}
	}
}

